﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MobileWeb.Models;

namespace MobileWeb.Helpers
{
    public class IntervalHelper
    {
        public static List<Area> GetAreas()
        {
            var xmlContent = XmlHelper.GetXmlContent("http://www.centar-bundek.hr/xml/codelist/areainterval");

            var elementList = xmlContent.Elements();
            var areas = new List<Area>();
            foreach (var interval in elementList)
            {
                var area = new Area()
                {
                    Id = Convert.ToInt32(interval.Element("id").Value),
                    Name = interval.Element("name").Value,
                    LowerLimit = Convert.ToInt32(interval.Element("LowerLimit").Value),
                    UpperLimit = Convert.ToInt32(interval.Element("UpperLimit").Value)
                };
                areas.Add(area);
            }

            return areas;
        }

        public static List<Floor> GetFloors()
        {
            var xmlContent = XmlHelper.GetXmlContent("http://www.centar-bundek.hr/xml/codelist/floor");

            var elementList = xmlContent.Elements();
            var floors = new List<Floor>();
            foreach (var interval in elementList)
            {
                var floor = new Floor()
                {
                    Id = Convert.ToInt32(interval.Element("id").Value),
                    Name = interval.Element("name").Value
                };
                floors.Add(floor);
            }

            return floors;
        }

        public static List<NumOfRooms> GetNumOfRooms()
        {
            var xmlContent = XmlHelper.GetXmlContent("http://www.centar-bundek.hr/xml/codelist/roomsnumber");

            var elementList = xmlContent.Elements();
            var numOfRooms = new List<NumOfRooms>();
            foreach (var interval in elementList)
            {
                var numOfRoom = new NumOfRooms()
                {
                    Id = Convert.ToInt32(interval.Element("id").Value),
                    Name = interval.Element("name").Value
                };
                numOfRooms.Add(numOfRoom);
            }

            return numOfRooms;
        }

        public static List<Price> GetPrices()
        {
            var xmlContent = XmlHelper.GetXmlContent("http://www.centar-bundek.hr/xml/codelist/priceinterval");

            var elementList = xmlContent.Elements();
            var prices = new List<Price>();
            foreach (var interval in elementList)
            {
                var price = new Price()
                {
                    Id = Convert.ToInt32(interval.Element("id").Value),
                    Name = interval.Element("name").Value,
                    UpperLimit = Convert.ToInt32(interval.Element("UpperLimit").Value),
                    LowerLimit = Convert.ToInt32(interval.Element("LowerLimit").Value)
                };
                prices.Add(price);
            }

            return prices;
        }
    }
}